
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL
{
    public class TS_Question_DAL
    {
        public static TS_Question_Collecion TS_Question_ListByPaging(int pageSize, int pageIndex)
        {
            TS_Question_Collecion list = new TS_Question_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_ListByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Question_Entity> pageList = cmd.ExecuteEntityList<TS_Question_Entity>();
                list. TS_Question_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }

        public static TS_Question_Entity TS_Question_View(System.Guid QuestionId)
        {
            TS_Question_Entity c = default(TS_Question_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_View");
                cmd.SetParameterValue("@QuestionId", QuestionId);
                c = cmd.ExecuteEntity<TS_Question_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Question_Entity TS_Question_ViewByQuestion(System.String Question)
        {
            TS_Question_Entity c = default(TS_Question_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_ViewByQuestion");
                cmd.SetParameterValue("@Question", Question);
                c = cmd.ExecuteEntity<TS_Question_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Question_Entity TS_Question_ViewByPreviewId(System.Guid PreviewId)
        {
            TS_Question_Entity c = default(TS_Question_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_ViewByPreviewId");
                cmd.SetParameterValue("@PreviewId", PreviewId);
                c = cmd.ExecuteEntity<TS_Question_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Question_Entity TS_Question_Add(TS_Question_Entity entity)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_Add");
                cmd.SetParameterValue("@QuestionId", entity.QuestionId);
                cmd.SetParameterValue("@ChapterId", entity.ChapterId);
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@MaterialsId", entity.MaterialsId);
                cmd.SetParameterValue("@Question", entity.Question);
                cmd.SetParameterValue("@QuestionType", entity.QuestionType);
                cmd.SetParameterValue("@ResultOptions", entity.ResultOptions);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static void TS_Question_Update(TS_Question_Entity entity)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_Update");
                cmd.SetParameterValue("@QuestionId", entity.QuestionId);
                cmd.SetParameterValue("@ChapterId", entity.ChapterId);
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@MaterialsId", entity.MaterialsId);
                cmd.SetParameterValue("@Question", entity.Question);
                cmd.SetParameterValue("@QuestionType", entity.QuestionType);
                cmd.SetParameterValue("@ResultOptions", entity.ResultOptions);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static void TS_Question_Delete(System.Guid QuestionId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_Delete");
                cmd.SetParameterValue("@QuestionId", QuestionId);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
        }
    }
}
